package com.study.utils;

import cn.hutool.core.io.FileUtil;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.util.List;

/**
 * @author zhuzi
 * 2024/10/6 15:47
 */
public class FileRenameDemo {

    @Test
    public void rename() {
        String fir = "/Volumes/aigo/MDD/";
        List<File> files = FileUtil.loopFiles(fir);
        for (File file : files) {

            String name = file.getName();
            if (StringUtils.equalsAny(name, ".DS_Store", "._.DS_Store")) {
                continue;
            }
            if (StringUtils.startsWith(name, ".")) {
                continue;

            }

            if (StringUtils.startsWith(name, "")) {
                String trim = StringUtils.replace(name, "", "").trim();
                System.out.println(trim);

                FileUtil.rename(file, trim, true);
            }

        }
    }

    @Test
    public void rems() {
        String filePath = "/Users/zhuzi/Downloads/B站/帝王之术";

        List<File> files = FileUtil.loopFiles(filePath);
        for (File file : files) {
            String name = file.getName();
            if (StringUtils.contains(name, "mp4")) {
                String newName = StringUtils.replace(name, "《帝王之术》之谋略篇：驭人驭己，经营化解，识人用人，谋划布局（下篇） - ", "");
                FileUtil.move(file, new File(file.getParent(), newName), true);
            }
        }
    }

    @Test
    public void rn() {
        FileUtil.rename(new File("/Volumes/aigo/MDD.mp4"), "HAHA.mp4", true);

    }

    @Test
    public void ls() {
        String filePath = "/Volumes/aigo/jpa";

        filePath = "/Users/zhuzi/workspace/myfile/电子书/";
        List<File> files = FileUtil.loopFiles(filePath);
        for (File file : files) {

            if (StringUtils.startsWith(file.getName(), ".")) {
                System.out.println(file.getPath());
                FileUtil.del(file);
            }
        }
    }
}
